<template>
  <div class="container">
    <div class="headerTitle"></div>

    <div class="formBox">
      <!-- <div class="formTitle">南浔区餐饮油烟智慧监管平台</div> -->
      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        class="login_form"
      >
        <el-form-item prop="username">
          <div class="inputTitle">账号：</div>
          <el-input
            class="elInputStyle"
            type=""
            placeholder="请输入账号"
            v-model.number="ruleForm.username"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <div class="inputTitle">密码：</div>
          <el-input
            class="elInputStyle"
            type="password"
            placeholder="请输入密码"
            v-model="ruleForm.password"
            autocomplete="off"
          ></el-input>
        </el-form-item>

        <el-button class="submitBtn" type="primary" @click="submitForm()"
          >登录</el-button
        >
      </el-form>
    </div>
  </div>
</template>

<script>
import { login } from '@/api/index'
export default {
  name: 'loginPage',
  props: {},
  components: {},
  data() {
    return {
      ruleForm: {
        username: '',
        password: '',
      },
      rules: {
        username: [{ required: true, message: '请输入账号', trigger: 'blur' }],
        password: [{ required: true, message: '请输入密码' }],
      },
    }
  },
  methods: {
    async submitForm() {
      const res = await login({
        loginAccount: this.ruleForm.username,
        loginPassword: this.ruleForm.password,
      })
      console.log(res)
      if (res.code === 1) {
        const now = Date.now() // 获取当前时间戳
        const loginTimeout = 12 * 60 * 60 * 1000 // 设置登录超时时间（1小时，单位为毫秒）

        localStorage.setItem('wangneng_token', res.data.token)
        localStorage.setItem('wangneng_loginTimestamp', now)
        localStorage.setItem('wangneng_loginTimeout', loginTimeout)
        this.$router.push('/index')
      }else {
        this.$message.error(res.msg)
      }
      // this.$store.commit('storeToken', res.data)

      //   localStorage.setItem('nanxun_id', res2.data.id)
      //   this.$router.push({
      //     path: 'index',
      //     query: {
      //       identity: res2.data.id,
      //     },
      //   })
    },
  },
  created() {},
  mounted() {},
  watch: {},
  computed: {},
  filters: {},
}
</script>

<style scoped lang="scss">
.headerTitle {
  z-index: 99;
  background-image: url('@/assets/allPic/head.png');
  background-size: cover;
  background-repeat: no-repeat;
  position: relative;
  box-sizing: border-box;
  width: 1920px;
  height: 92px;
  position: absolute;
  left: 0;
  top: 0;
}
.container {
  width: 1920px;
  height: 1080px;
  background-image: url('@/assets/allPic/登录页.png');
  .formBox {
    position: absolute;
    right: 140px;
    top: 330px;
    background-color: #fff;
    padding: 40px;
    border-radius: 10px;
    .formTitle {
      letter-spacing: 0.1em;
      margin-bottom: 20px;
      font-size: 40px;
      font-family: Alimama ShuHeiTi;
      color: #021770;
      font-weight: 800;
    }
    .elInputStyle {
      width: 447px;
      height: 50px;
    }
    ::v-deep .el-input__inner {
      background-color: #ededed !important;
      height: 50px;
      line-height: 50px;
      width: 447px;
      border-radius: 6px;
    }
    ::v-deep .el-input__inner::-webkit-input-placeholder {
      /* WebKit browsers，webkit内核浏览器 */
      color: #b3b3b3;
      letter-spacing: 0.3em;
      font-size: 20px;
      border-radius: 6px;
    }
    ::v-deep .el-input__inner:-moz-placeholder {
      /* Mozilla Firefox 4 to 18 */
      color: #b3b3b3;
      letter-spacing: 0.2em;
      font-size: 20px;
      border-radius: 6px;
    }
    ::v-deep .el-input__inner::-moz-placeholder {
      /* Mozilla Firefox 19+ */
      color: #b3b3b3;
      letter-spacing: 0.2em;
      font-size: 20px;
      border-radius: 6px;
    }
    ::v-deep .el-input__inner:-ms-input-placeholder {
      /* Internet Explorer 10+ */
      color: #b3b3b3;
      letter-spacing: 0.2em;
      font-size: 20px;
      border-radius: 6px;
    }

    .el-form-item {
      margin-bottom: 10px;
    }
    .inputTitle {
      font-weight: 800;
      font-size: 24px;
      color: #000;
      margin-bottom: 16px;
      letter-spacing: 0.3em;
      font-family: Source Han Sans;
    }
    .submitBtn {
      width: 447px;
      height: 50px;
      text-align: center;
      font-size: 22px;
      font-weight: 800;
      letter-spacing: 0.4em;
      line-height: 50px;
      background-color: #448be3;
      padding: 0;
      margin-top: 40px;
      border-radius: 6px;
    }
    .jiaoyanmaInp {
      display: flex;
      align-items: center;
      justify-content: space-between;
      width: 447px;
      .loginImg {
        width: 200px;
        height: 50px;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .elInputStyle {
        width: 220px;
        height: 50px;
      }
      ::v-deep .el-input__inner {
        background-color: #ededed !important;
        height: 50px;
        line-height: 50px;
        width: 220px;
        border-radius: 6px;
      }
    }
  }
}
</style>
